<!-- <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
</body>
</html>
<script src="./json.js"></script>
<script>
    var x = document.getElementById("app")
    try{
        if(!x) throw("此操作为错误")
        if(x == undefined) throw("此操作为undefined")
        if(x.innerHTML == '') throw("此操作为空")
    }catch(err){
        console.log(err)
    }

    function bibao(){
        console.log(name)
        return function(){
            var name = 22
            return name
        }
        
    }
    bibao()()
    console.log() -->

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<button onclick="send()">dengl</button>
        <canvas></canvas>
        <img id="ttss">
	</body>
    <script>
        var index = 0
        //跨页面API必须写在生命周期mounted中
        var channel = new BroadcastChannel('myChannel');
        //点击事件没有跨页面通信的 所以点击后只会在本页面触发
        
        function send(){
            index ++
            channel.postMessage(index)
            //监听chanel.postMessage发生增加时触发
        }
        channel.onmessage = (event) =>{
            console.log(event)
        }
        var imgs = document.getElementById("ttss")
        var csn = document.querySelector("canvas")
        var crs = csn.getContext("2d")
        var img = new Image() 
        img.onload = function(){
            //this 指向的是img这个对象
            csn.width = this.width
            csn.height = this.height
            crs.drawImage(this,0,0)
        }
        img.src = "./img/456.jpg"
    </script>

    <script>
        function add(x){
            if(x === 1){
                return 1
            }
            return x*add(x-1)
        }
        console.log(add(5))
    </script>
</html>
</script>